/**
 * docs:  https://log4js-node.github.io/log4js-node/dateFile.html
 */

const path = require('path');
const log4js = require('log4js');
const logDir = path.join(__dirname,'logs');
log4js.configure({
    appenders: {
        out: {
            type: 'stdout'
        },
        access: {
            type: 'dateFile',
            filename: path.join(logDir,'access.log'),
            alwaysIncludePattern:true,
            compress:true,
            keepFileExt:true,
        }
    },
    categories: {
        access: {
            appenders: ['access'],
            level: 'info'
        },
        default: {
            appenders: ['out'],
            level:'debug'
        }
    }
});

const accessLogger = log4js.getLogger('access');
const defaultLogger = log4js.getLogger();

const Koa = require('koa');
const app = new Koa();

app.use(async (ctx) => {
    accessLogger.info(`url:${ctx.request.url}`);
    ctx.response.body = 'hello world!XXX';
});

app.listen(3000, () => {
    defaultLogger.info('server start at http://localhost:3000');
});

// defaultLogger.info('process.env:',process.env);
